package com.controller.supply;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.common.StringUtils;
import com.common.db.RedisUtils;
import com.common.model.Global;
import com.common.model.UserTypeEnum;
import com.common.spring.SpringMvcUtils;
import com.model.supply.SupplyUserModel;

/**
 * 供应商准入管理
 */

@Controller
public class SupplyController {

	@RequestMapping("supply/bydMergeStore")
	public Map<String, String> bydMergeStore() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/bydTest")
	public Map<String, String> bydTest() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/bydStore")
	public Map<String, String> bydStore() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	/**
	 * url映射
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping("supply/module")
	public Map<String, String> module() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/complete")
	public Map<String, String> complete() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/bid")
	public Map<String, String> bid() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/good")
	public Map<String, String> good() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("supply/group")
	public Map<String, String> billGroup() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("/supply/changePwd")
	public Map<String, String> changePwd() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/ent/info")
	public Map<String, String> entinfo() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/ent/mySupply")
	public Map<String, String> mySupply() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/ent/user")
	public Map<String, String> entuser() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/supply/info")
	public Map<String, String> info() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/supply/saleLabelSupplyAudit")
	public Map<String, String> saleLabelSupplyAudit() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/supply/admit")
	public Map<String, String> admit() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("/supply/offer")
	public Map<String, String> offer() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		map.put("key2", "value-2");
		map.put("key3", "value-2");
		return map;
	}

	@RequestMapping("supply/user")
	public Map<String, String> user() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("key1", "value-1");
		return map;
	}

	@RequestMapping("/supply/SupplyOfdefault")
	public String sysdefault(HttpServletRequest request) {
		return "supply/SupplyOfdefault";
	}

	@Autowired
	RedisUtils redisUtils;

	@RequestMapping("/supply/logout")
	public String logout(HttpServletRequest request) {
		String userTypeString = (String) request.getSession().getAttribute("userType");
		if (!StringUtils.isNotNull(userTypeString)) {
			return "supply/login";
		}
//		if (userTypeString.equals(UserTypeEnum.XYUser.getValue())) {
//			SysUser sysUser = SpringMvcUtils.getSysUser();
//			redisUtils.del(Global.REDIS_USER_PREFIX + userTypeString + "-" + sysUser.getUserid());
//		} else {
//			SupplyUserModel userModel = SpringMvcUtils.getSupplyUser();
//			redisUtils.del(Global.REDIS_USER_PREFIX + userTypeString + "-" + userModel.getUserId());
//		}
		SupplyUserModel userModel = SpringMvcUtils.getSupplyUser();
		if (userModel == null) {
			return "supply/login";
		}
		redisUtils.del(Global.REDIS_USER_PREFIX + UserTypeEnum.SupplyUser.getValue() + "-" + userModel.getUserId());
		request.getSession().invalidate();
		return "supply/login";
	}

	/**
	 * 供应商用户登陆地址跳转
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/supply/login")
	public String login(HttpServletRequest request) {
		return "supply/login";
	}

}
